#include <iostream>

#include "sigamer.h"

/** 
* @brief Jumps to tne next state of game 
*/
void
SIGamer::nextState(InSignal iSignal)
{
    switch (state_)
    {
        case STARTGAME:
            curQCost_ = 10;
            curQNum_ = 1;
            curThemeNum_ = 1;
            score_[0] = score_[1] = score_[2] = score_[3] = 0;
        case INIT:
            ++state_;
            break;
        case QREADING:
            if (iSignal == GOTO)
            {
                ++state_;
            } /*             if (iSignal == GOTO) */
            else if (iSignal >= REDPLAYER && iSignal <= YELLOWPLAYER)
            {
                prevState_ = QREADING;
                state_ = A1WAIT;
                curPlayer_ = iSignal;
            } /* else if (iSignal >= REDPLAYER */
            break;
        case ASWAIT:
            if (iSignal >= REDPLAYER && iSignal <= YELLOWPLAYER)
            {
                prevState_ = ASWAIT;
                state_ = A1WAIT;
                curPlayer_ = iSignal;
            } /* else if (iSignal >= REDPLAYER */
            else
                nextQuestion();
            break;
        case A1WAIT:
            if (iSignal == PLUS)
            {
                score_[curPlayer_] += curQCost_;
                nextQuestion();
            } /*             if (iSignal == PLUS) */
            else if (iSignal == MINUS)
            {
                score_[curPlayer_] -= curQCost_;
                state_ = prevState_;
            } /*             else if (iSignal == MINUS) */
            break;
    } /*     switch (state_) */
} /* SIGamer::nextState() */

void
SIGamer::nextQuestion()
{
    if (curQNum_ < 5)
    {
        ++curQNum_;
        curQCost_ += 10;
    } /*             if (curQNum_ < 5) */
    else
    {
        curQNum_ = 1;
        curQCost_ = 10;
        ++curThemeNum_;
    } /*             else */
    state_ = QREADING;
} /* SIGamer::nextQuestion() */

